using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Xeml.Document;

namespace Xeml.Visualization
{
    public class VisSplitDot :  VisualTimeElement
    {

        #region Fields
        private VisStory visualStory; 
        #endregion

        #region Properties
        public override TimeSpan Time
        {
            get
            {
                return this.visualStory.Time;
            }
            set
            {
                throw new Exception("The method or operation is not implemented.");
            }
        }

        public VisStory VisualStory
        {
            get { return visualStory; }
        } 
        #endregion
        
        #region Constructors
        public VisSplitDot(VisStory vstory, float x, float y, SizeF size)
        {
            this.visualStory = vstory;
            this.x = x;
            this.y = y;
            this.Size = size;
            //this.visualStory.SelectionChanged += new EventHandler(visualStory_SelectionChanged);
            if(this.visualStory.Story.Content is StorySplit)
                (this.visualStory.Story.Content as StorySplit).TimePointHasChanged += new EventHandler<Mpi.Common.PropertyHasChangedEventArgs<TimeSpan>>(VisSplitDot_TimePointChanged);
        }

        void VisSplitDot_TimePointChanged(object sender, Mpi.Common.PropertyHasChangedEventArgs<TimeSpan> e)
        {
            base.OnXLocationUpdateNeeded(e);
        }

      

        void visualStory_SelectionChanged(object sender, EventArgs e)
        {
            this.selected = this.visualStory.Selected;
        } 
        #endregion

        #region Methods


        public override bool Selected
        {
            get
            {
                return this.visualStory.Selected;
            }
            set
            {
                this.visualStory.Selected = value;
                if (value)
                    OnSelection();
                else
                    OnDeSelection();
            }
            //get
            //{
            //    return base.Selected;
            //}
            //set
            //{
            //    if (this.visualStory.Selected && value == false)
            //        return;
            //    else
            //        base.Selected = value;
            //}
        }

        public override void TrySelect(int x, int y, bool multiSelect)
        {
            if (multiSelect)
            {
                if (this.shape.IsVisible(x, y))
                {
                    this.Selected = !this.Selected;
                    OnTouched();
                }
            }
            else
            {
                if (this.shape.IsVisible(x, y))
                {
                    this.Selected = true;
                    OnTouched();
                }
                //else
                //    this.Selected = false;
            }
        }

        //protected override void OnSelection()
        //{
        //    this.visualStory.Selected = true;
        //    base.OnSelection();
        //}

        protected override void SetShape()
        {
            float x = this.x - (this.Size.Width / 2f);
            float y = this.y - (this.Size.Height / 2f);
            this.shape = new System.Drawing.Drawing2D.GraphicsPath();
            this.shape.AddEllipse(x, y, this.size.Width, this.size.Height);
        } 
        #endregion
    }

}
